package com.baeldung.bidirect;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by dzy on 2018/9/2
 */
public class CustomListSerializer extends StdSerializer<List<Item4>> {

  public CustomListSerializer(){
    this(null);
  }

  protected CustomListSerializer(Class<List<Item4>> t) {
    super(t);
  }

  @Override
  public void serialize(List<Item4> items, JsonGenerator gen, SerializerProvider provider) throws IOException {
    List<Integer> ids = new ArrayList<>();
    for (Item4 item : items) {
      ids.add(item.id);
    }
    gen.writeObject(ids);
  }
}
